package com.walleipt.corgi.api.chain;

import java.util.ArrayList;
import java.util.List;

public class CommandChain<T extends Context> implements Command<T>
{
	List<Command<T>> commands = new ArrayList<Command<T>>();
	
	public List<Command<T>> getCommands()
	{
		return commands;
	}

	public void setCommands(List<Command<T>> commands)
	{
		this.commands = commands;
	}

	@Override
	public boolean execute(T context) throws Exception
	{
		for( Command<T> command : commands )
		{
			boolean result = command.execute(context) ;
			if( !result )
				return false ;
		}
		return true;
	}

}
